package nl.ypmits.utils.as3.bitmap.camera {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.media.Camera;
	import flash.media.Video;

	/**
	 * @author Dave Lenz
	 */
	public class CameraBitmap extends Sprite {
		private var cam : Camera;
		private var vid : Video;
		private var bm : Bitmap;
		private var bmd : BitmapData;
		
		public function CameraBitmap( width : Number = 320, height : Number = 240, fps : int = 25 ) {
			cam = Camera.getCamera();
			cam.setMode( width, height, fps );
			vid = new Video( width, height );
			vid.attachCamera( cam );
			
			bmd = new BitmapData( width, height, false );
			bm = new Bitmap( bmd );
			addChild( bm );
			
			addEventListener( Event.ENTER_FRAME, enterHandler );
		}
		
		
		public function getBitmap() : Bitmap {
			return bm;
		}

		
		private function enterHandler(event : Event) : void {
			var m : Matrix = new Matrix( -1, 0, 0, 1, bmd.width, 0 );
			bmd.draw( vid, m );
		}
		
		
	}
}
